home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <ctype.h>
- #include "crcpchdr.h"
-
- int initialize(argc,argv)
- int argc;
- char *argv[];
- {
- char c, d;
- char *options, *getenv();
- int gn_fl;
- /* Initialize defaults which options can change */
- if ((options=getenv(HPATH))==NULL) stccpy(hpath,HELP_PATH,sizeof(hpath));
- else stccpy(hpath,options,sizeof(hpath));
- if ((options=getenv(IPATH))==NULL) stccpy(ipath,INFO_PATH,sizeof(ipath));
- else stccpy(ipath,options,sizeof(ipath));
- if ((options=getenv(FPATH))==NULL) stccpy(fpath,FORT_PATH,sizeof(fpath));
- else stccpy(fpath,options,sizeof(fpath));
- if ((options=getenv(EDIT1))==NULL) stccpy(sys_editor,SYS_EDITOR,sizeof(sys_editor));
- else stccpy(sys_editor,options,sizeof(sys_editor));
- if ((options=getenv(EDIT2))==NULL) stccpy(alt_editor,ALT_EDITOR,sizeof(alt_editor));
- else stccpy(alt_editor,options,sizeof(alt_editor));
-
- stccpy(exit_pw,EXIT_PW,PWDLEN);
- stccpy(suspend_pw,SUSPW,PWDLEN);
-
- if (debug) printf("hpath,ipath,fpath,seditor,aeditor=%s,%s,%s,%s,%s\r\n",
- hpath,ipath,fpath,sys_editor,alt_editor);
-
- /* Process options, if any */
- if (argc>1) while (--argc) {
- if (argv[argc][0]=='?') {
- option_ins();
- return 1000;
- }
- uppercase(argv[argc]);
- gn_fl = TRUE;
-
- if (argv[argc][0]=='-') {
- switch(argv[argc][1]) {
- case 'H': stccpy(hpath,argv[argc]+2,sizeof(hpath));
- break;
- case 'F': stccpy(fpath,argv[argc]+2,sizeof(fpath));
- break;
- case 'I': stccpy(ipath,argv[argc]+2,sizeof(ipath));
- break;
- case 'P': switch(argv[argc][2]) {
- case 'X': stccpy(exit_pw,argv[argc]+3,sizeof(exit_pw));
- break;
- case 'S': stccpy(suspend_pw,argv[argc]+3,sizeof(suspend_pw));
- break;
- default: gn_fl = FALSE;
- }
- case 'D': if (argv[argc][2]=='O') deftflag = FALSE;
- break;
- default: gn_fl = FALSE;
- }
- }
- else if (!strcmp(argv[argc],"OFFLINE")) sys_test = TRUE;
- else if (!strcmp(argv[argc],"EXPERT")) defbeginner = FALSE;
- else if (!strcmp(argv[argc],"NOTIMEOUT")) notimeout = TRUE;
- else if (!strcmp(argv[argc],"FORK")) fork_allowed = TRUE;
- else if (!strcmp(argv[argc],"WILDCARDS")) wildcards = TRUE;
- else if (!strcmp(argv[argc],"AVAILABLE")) sysop_there = TRUE;
- else if (!strcmp(argv[argc],"PRTON")) prton = TRUE;
- else if (!strcmp(argv[argc],"DEBUG")) debug = TRUE;
- else if (!strcmp(argv[argc],"DEF300")) cb = 1;
- else gn_fl = FALSE;
-
- if (gn_fl) ;
- else if (!strcmp(argv[argc],"NEWLOG")) newlog = TRUE;
- else if (!strcmp(argv[argc],"NOLOG")) nolog = TRUE;
- else if (!strcmp(argv[argc],"NONEWS")) nonews = TRUE;
- else if (!strcmp(argv[argc],"FORTUNE")) fort_une = TRUE;
- else if (!strcmp(argv[argc],"TERMWIDTH")) termwidth = worknum;
- else if (!strcmp(argv[argc],"FORTGAP")) fort_gap = worknum;
- else if (!strcmp(argv[argc],"NOINTRO")) intro = FALSE;
- else if (!strcmp(argv[argc],"AUTOFB")) autofb = TRUE;
- else if (!strcmp(argv[argc],"1200B")) h1200b = TRUE;
- else if (!strcmp(argv[argc],"NOALTBAUD")) altbd = FALSE;
- else if (worknum=stoi(argv[argc]));
- else printf("Invalid option '%s' ignored.\r\n",argv[argc]);
- }
-
- /* Try to read command table from disk file */
- if ((commands=read_cmds())==NULL) {
- printf("Can't read command table file: '%s'\r\n",CMDFILE);
- return 8;
- }
-
- /* Check integrity of system directories */
- if (sysdir("",MAILBOX)) exit(baddir(MAILBOX));
- else if (sysdir("",MESSAGES)) exit(baddir(MESSAGES));
- else if (sysdir("",USR_ROOT)) exit(baddir(USR_ROOT));
- else if (sysdir("",hpath)) exit(baddir(hpath));
- else if (sysdir("",ipath)) exit(baddir(ipath));
- /* Able to CHDIR to all of them, proceed */
-
- /* Get pointer array for message system */
- if ((list=(struct dir_entry **)getmem(999*2))==NULL) {
- printf("Can't allocate memory for msg array.\r\n");
- return 9;
- }
-
- stccpy(user_root,USR_ROOT,sizeof(user_root)); /* ONE AND ONLY DEFINITION OF user_root */
-
- /* Cut off access from local printer and BREAK interrupt */
- if (!sys_test) brkset(OFF);
- if (!prton) printer(OFF);
- if (newlog) eraselog();
- openlog();
- logevent("LOG OPENED");
- if (fort_une) reset_fortf(); /* Open fortune file if selected */
- return 0;
- }
-
- int log_on()
- {
- char c, d;
- /* Wait for caller or local keyboard function */
- logon:
- init_vars(); /* Initialize/refresh/default system variables */
- baud="(system-test)";
- parity="N";
- wordlen="*";
-
- reset: baud = bdt[cb]; /* Default (last) baud rate */
- parity = "N"; /* Try no parity first */
- stopbits = "1"; /* Always one stop bit */
- wordlen = "8"; /* And eight bit word */
-
- /* Install trial modem settings */
- minit(baud,parity,wordlen,stopbits,h1200b?"h":"");
- if (!dsr()) printf("\r\n*USER DISCONNECT AT %s*\r\n",timedate());
- while(!dsr()) { /* Wait for phone call */
- if (bdos(KBHIT)) {
- if (!bdos(CONSINP)) local_function(bdos(CONSINP));
- else breakin_ins();
- }
- } /* Below logic auto-baud detect. */
- /* Stolen from RBBS-PC (BASIC) pgm */
- /* In either case, we read a CR to detect parity */
- while (dsr()) { /* While someone on the line */
- if (bdos(KBHIT)) { /* If a key typed, */
- if ((c=bdos(CONSINP))!='\r') { /* Get and see if CR */
- /* Nop -- not a CR */
- /* See what user typed */
- if (debug) printf("usrtyp:`%c'=%d\r\n",c,c);
- /* Look for carriage return with */
- if (c==('\r'|0x80)) { /* high bit on? if so, */
- baud=bdt[cb]; /* try current baud rate, */
- parity = "E"; /* Using Even parity */
- wordlen = "7"; /* and seven bits */
- }
- else {
- if (altbd) baud=bdt[cb=cb?0:1]; /* Toggle baud rate */
- parity = "N"; /* Using No parity */
- wordlen = "8"; /* and eight bits */
- }
- minit(baud,parity,wordlen,stopbits,h1200b?"h":"");/* Change UART */
- if (debug) printf("%s,%s,%s,%s\r\n",baud,parity,wordlen,stopbits);
- } /* END Character not CR */
- else break; /* Character was CR */
- } /* Key was pressed */
- } /* While dsr() */
-
-
- if (debug) { /* Peek & Say real baud if debug */
- c = inp(LCR);
- printf("LCR=%x\r\n",c);
- outp(LCR,c|0x80); /* SET DLAB */
- printf("rb:%x%x\r\n",inp(DLM),inp(DLL));
- outp(LCR,c);
- }
-
- if (!dsr()) goto reset; /* If he hung up, forget him! */
-
- systime(&login_hh,&login_mm,&login_ss,&login_ms); /* Get time of call */
- printf("\r\n\r\n%s online\r\n\n",SYSNAME);
- if (intro) help(SYSNEWS,"t");
- cr();
- trynpw:
- quit = FALSE;
- output = TRUE;
- printf("Enter %s ID or hit <ENTER>: ",SYSNAME);
- disp_reply("",user_id,sizeof(user_id));
- seek_user:
- stptok(user_id,workstr,9,BADUSRCHRS);
- stccpy(user_id,workstr,sizeof(user_id));
- uppercase(user_id);
- if (user_id[0]=='\0') {
- help(HLP_LOGON,"t");
- if (dsr()) goto trynpw;
- else goto logon;
- }
- else if (sysdir(user_id,user_root)) {
- printf("You said: %s.\r\nPress <ENTER> if correct, or re-type:\r\n",
- user_id);
- disp_reply("",workstr,sizeof(user_id));
- if (workstr[0]=='\0') {
- printf("Ok %s, you will be placed on the %s directory.\r\n",
- user_id,DEFLT_DIR);
- sysdir(DEFLT_DIR,user_root);
- stccpy(home_dir,DEFLT_DIR,sizeof(home_dir));
- mputs("Read the HELP section in order to obtain your own,\r\n");
- mputs("private directory.\r\n");
- cr();
- }
- else {
- stccpy(user_id,workstr,sizeof(user_id));
- goto seek_user;
- }
- }
- else stccpy(home_dir,user_id,sizeof(home_dir));
-
- uppercase(home_dir);
- no_account = !strcmp(home_dir,DEFLT_DIR); /* NO_ACCOUNT TRUE iff on PUBLIC */
-
- read_userfile(); /* Go read user info file */
- if (!test_password()) { /* If password, ask for it */
- printf("Incorrect password.\r\n");
- printf("If you are a newcomer, please type '%s'.\r\n",DEFLT_DIR);
- goto trynpw;
- }
- systime(&login_hh,&login_mm,&login_ss,&login_ms); /* Reset to time of logon */
- noforcenow = nousrto; /* We are timing him from now unless NOUSRTO */
- sysdir(home_dir,user_root); /* Come back to home directory */
- stccpy(cur_dir,home_dir,sizeof(cur_dir));/* record this as current directory */
- stccpy(cur_root,user_root,sizeof(cur_root));/* Make sure we're in right world */
-
- cls(); /* Clear user's screen if we know how */
- if (not_terminal) { /* THIS USER WAS NOT SUSPENDED */
- if (no_account) { /* Is this the PUBLIC acct ? */
- beginner = TRUE; /* Set beginner for him */
- printf("%s and welcome to %s!\r\n",good_morning(),SYSNAME);
- sprintf(workstr,"VISITOR: %s",user_id);
- }
- else if (timeson>1) {
- printf("%s and welcome back %s!\r\n",good_morning(),usname());
- if (strcmp(laston,date())) printf("You last called on %s",laston);
- else printf("You called earlier today");
- printf("; %d total calls.\r\n",timeson);
- expertstatus();
- cr();
- sprintf(workstr,"LOGON: %s",user_id);
- }
- else {
- printf("%s, %s!\r\nWelcome to your new account.\r\n",good_morning(),user_id);
- printf("Forward all system correspondence to %s. Enjoy.\r\n",SYSOP);
- sprintf(workstr,"LOGON: %s <-- new user",user_id);
- typeifexist(ipath,FIRSTMSG_MSG,FALSE);
- }
- }
- else sprintf(workstr,"LOGON: *%s*",user_id);
-
- logevent(workstr);
- if (not_terminal) return 0;
- else {
- printf("\r\nSorry, this account is no longer active.\r\n");
- printf("Please contact %s.\r\n",SYSOP);
- stccpy(syspw,suspend_pw,sizeof(syspw));
- log_off('T',"",FALSE);
- return 1; /* COULDNT LOG THIS GUY ON */
- }
- }
-
- log_off(c,options,quiet)
- char c;
- int quiet;
- char *options;
- {
- char d;
- int gn_fl;
-
- write_userfile(); /* Write user info back to disk */
- logevent("LOGOFF");
- if (dsr()) {
- noforcenow = TRUE; /* Don't force during LOGOFF */
- if (c=='Q') {
- cls();
- printf("\r\n\r\n Goodbye!\r\n");
- printf("\r\n(hang up or press ENTER)\r\n\r\n");
- return; /* Quit quickly if 'Q' used */
- }
- else if (c=='T') goto quick_off; /* Or shoo him off if Terminal */
- gn_fl = FALSE;
- if (dsr() && ((autofb && !quiet) || (gn_fl=find_option(options,'f')))) {
- if (gn_fl) d='Y';
- else d=*disp_reply("Wish to leave feedback ? ",file_buffer,4);
- if (toupper(d)=='Y') ask_sysop('Q',"","fq");
- }
- if (c=='X') goodbye(user_id); /* Leave if 'X' cmmd was used */
- cls();
- printf("Goodbye %s! Call again soon.\r\n\n",strcmp(user_id,DEFLT_DIR)?user_id:"");
- printf("%s: %s\r\n\n",SYSNAME,SYSOWNER); /* Say goodbye */
- sprintf(workstr,"Off at: %s\r\n",timedate());
- printf(workstr);
- printf("Connect time: %s\r\n\n\n",elapsed_time(cnct_seconds()));
- any_last_news(); /* Whatever we may want to publish before logoff */
- if (fort_une && !nousrfort) fortune(randint(fort_gap)); /* Do fortune if requested */
- }
- quick_off:
- hangup(); /* Hangup if 'Q' not used */
- closelog(); /* Close out the log for safety */
- openlog();
- return;
- }
-